class ListController < ApplicationController
  include ListHelper

  def product_list
    @good_info = GoodsInfo.all
  end

  def click_get_goods
    @goods_inventory = GoodsInventory.all
    render :json => @goods_inventory
  end

  def ajax_goods
    @good_info = CartGood.all
    render :json => @good_info
  end

  def save_cart_goods
    good = {:sort => params[:sort], :name => params[:name], :unit => params[:unit], :price => params[:price], :count => 1, :free_count => 0}
    save(params,good)
    render :json => {:status => true}
  end

  def ajax_goods_count
    all = delete_good(0) # all_count = 0
    render :json => all
  end

  def delete_good(count)
    CartGood.all.each { |i|
      count = count+i[:count].to_i
      delete_good_info(i)
    }
    return count
  end
end
